﻿// =====================================================================
//
//  This file is part of the Microsoft Dynamics CRM SDK code samples.
//
//  Copyright (C) Microsoft Corporation.  All rights reserved.
//
//  This source code is intended only as a supplement to Microsoft
//  Development Tools and/or on-line documentation.  See these other
//  materials for detailed information regarding Microsoft code samples.
//
//  THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
//  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
//  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//  PARTICULAR PURPOSE.
//
// =====================================================================
using System;
using System.Runtime.Serialization;

namespace Microsoft.Xrm.Sdk.Metadata
{
	[DataContract(Name = "DateTimeAttributeMetadata", Namespace = XmlNamespaces.V5.Metadata)]
	public sealed class DateTimeAttributeMetadata : AttributeMetadata
	{
		#region Fields
		private static readonly DateTime _minDateTime = new System.DateTime(1900, 1, 1, 0, 0, 0, DateTimeKind.Utc);
		private static readonly DateTime _maxDateTime = new System.DateTime(9999, 12, 30, 23, 59, 59, DateTimeKind.Utc);

		private DateTimeFormat? _format;
		private ImeMode? _imeMode;
		#endregion

		#region Constructors
		public DateTimeAttributeMetadata()
			: this(null)
		{
		}

		public DateTimeAttributeMetadata(DateTimeFormat? format)
			: this(format, null)
		{
		}

		public DateTimeAttributeMetadata(DateTimeFormat? format, string schemaName)
			: base(AttributeTypeCode.DateTime, schemaName)
		{
			this.Format = format;
		}
		#endregion

		#region Properties
		public static DateTime MinSupportedValue
		{
			get
			{
				return _minDateTime;
			}
		}

		public static DateTime MaxSupportedValue
		{
			get
			{
				return _maxDateTime;
			}
		}

		/// <summary>
		/// Required for CreateAttribute
		/// Valid for UpdateAttribute
		/// </summary>
		[DataMember]
		public DateTimeFormat? Format
		{
			get { return this._format; }
			set { this._format = value; }
		}

		/// <summary>
		/// Valid for CreateAttribute
		/// Valid for UpdateAttribute
		/// </summary>
		[DataMember]
		public ImeMode? ImeMode
		{
			get { return _imeMode; }
			set { _imeMode = value; }
		}
		#endregion
	}
}
